<%-- 
    Document   : index
    Created on : May 29, 2013, 5:20:00 PM
    Author     : Anna SAELEE
--%>

<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link type="text/css" rel="stylesheet" href="style.css"/>
        <title>Gestion de la résidence d'étudiant</title>
    </head>
    <%  Connection conn;
        Statement stmt;
        ResultSet rs;
        try {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dormitorymanagement", "root", "root");
            stmt = conn.createStatement();%>
    <body>
        <div class="wrapper">
            <div class="header"></div>
            <div class="navigator"> <a href="#">MENU</a> > <a href="#">SUBMENU</a> 30*1000 </div>
            <div class="workspace">
                <%@include file="connect.jsp" %>
                <div class="workspace2">
                    <h3>Nouvelles</h3><br/>
                    <div class="workspace2-1">
                        <h4>Nouvelle de la résidence</h4><br/>
                        <table border="0" width="100%">
                            <col width="5">
                            <col width="170">
                            <col width="20">
                            <%
                                String sql = "SELECT nid, date, subject FROM news WHERE cid IN"
                                        + "(SELECT cid FROM category WHERE cname='Residence')"
                                        + "ORDER BY date DESC LIMIT 4";
                                rs = stmt.executeQuery(sql);
                                while (rs.next()) {%>
                            <form method="post" action="ReadNews" name="moreDetail">
                                <tr>
                                <input type="hidden" name="nid" value="<%= rs.getString("nid")%>"/>
                                <td><%= rs.getString("date")%></td>
                                <td><%= rs.getString("subject")%></td>
                                <td style="text-align:right"><input class="submitlink" type="submit" name="notConfirm" value="more info."/></td>
                                </tr>
                            </form>

                            <% }%>
                        </table>
                    </div>
                    <div class="workspace2-2">
                        <h4>Générales nouvelles</h4><br/>
                        <table border="0" width="100%">
                            <col width="5">
                            <col width="170">
                            <col width="20">
                            <%
                                sql = "SELECT nid, date, subject FROM news WHERE cid IN"
                                        + "(SELECT cid FROM category WHERE cname='General')"
                                        + "ORDER BY date DESC LIMIT 4";
                                rs = stmt.executeQuery(sql);
                                while (rs.next()) {%>
                            <form method="post" action="ReadNews" name="moreDetail">
                                <tr>
                                <input type="hidden" name="nid" value="<%= rs.getString("nid")%>"/>
                                <td><%= rs.getString("date")%></td>
                                <td><%= rs.getString("subject")%></td>
                                <td style="text-align:right"><input class="submitlink" type="submit" name="notConfirm" value="more info."/></td>
                                </tr>
                            </form>

                            <% }%>
                        </table>
                    </div>
                    <div class="workspace2-3">
                        <h4>Annonces et Publicités</h4><br/>
                        <table border="0" width="100%">
                            <col width="5">
                            <col width="170">
                            <col width="20">
                            <%
                                sql = "SELECT nid, date, subject FROM news WHERE cid IN"
                                        + "(SELECT cid FROM category WHERE cname='Annonce' OR cname='Publicite')"
                                        + "ORDER BY date DESC LIMIT 4";
                                rs = stmt.executeQuery(sql);
                                while (rs.next()) {%>
                            <form method="post" action="ReadNews" name="moreDetail">
                                <tr>
                                <input type="hidden" name="nid" value="<%= rs.getString("nid")%>"/>
                                <td><%= rs.getString("date")%></td>
                                <td><%= rs.getString("subject")%></td>
                                <td style="text-align:right"><input class="submitlink" type="submit" name="notConfirm" value="more info."/></td>
                                </tr>
                            </form>

                            <% }%>
                        </table>
                    </div>
                    <div class="workspace2-4">
                        <h4>Autres</h4><br/>
                        <table border="0" width="100%">
                            <col width="5">
                            <col width="195">
                            <%
                                sql = "SELECT nid, date, subject FROM news WHERE cid IN"
                                        + "(SELECT cid FROM category WHERE cname!='Residence' AND cname!='Annonce' "
                                        + "AND cname!='Publicite' AND cname!='General') ORDER BY date DESC LIMIT 4";
                                rs = stmt.executeQuery(sql);
                                while (rs.next()) {%>
                            <form method="post" action="ReadNews" name="moreDetail">
                                <tr>
                                <input type="hidden" name="nid" value="<%= rs.getString("nid")%>"/>
                                <td><%= rs.getString("date")%></td>
                                <td><%= rs.getString("subject")%></td>
                                <td><input class="submitlink" type="submit" name="notConfirm" value="lien"/></td>
                                </tr>
                            </form>

                            <% }%>
                        </table>
                    </div>
                </div>
                <%@include file="sidespace.jsp" %>
            </div>
            <div class="footer"> FOOTER 80*1000 </div>
        </div>
    </body>
    <% } finally {
            out.close();
        }
    %>
</html>
